//
//  SsehHomePageViewController.m
//  SsehMaster
//
//  Created by 杨阳 on 2018/8/3.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "SsehHomePageViewController.h"
#import "OrderDetailTableViewCell.h"
#import "MJRefresh.h"
#import "OrderDetailsViewController.h"
#import "OrderInforModel.h"
#import "BannerModel.h"
#import "XRCarouselView.h"
#import "NSString+BRSize.h"
#import <TencentLBS/TencentLBS.h>
#import "AddMaterialsViewController.h"
#import <MapKit/MapKit.h>
#import "SDCityPickerViewController.h"
#import "SDCityInitial.h"
#import "SDCityModel.h"

#import "SsehMJFooterTool.h"
#import "SsehMJHeaderTool.h"
#import "SsehLocationConverter.h"
#import "NodataView.h"

#import "OrderCompleteUpLoadImageViewController.h"

@interface SsehHomePageViewController ()<UITableViewDelegate,UITableViewDataSource,TencentLBSLocationManagerDelegate>

@property (nonatomic,strong) UITableView * ssehTableView;

@property (nonatomic,strong) NSMutableArray * dataSource;

@property (nonatomic,strong) BannerModel * bannerModel;

@property (nonatomic, strong) XRCarouselView *carouselView;

@property (nonatomic,strong) UILabel * leftTitleItemLabel;

@property (nonatomic,strong) UIImageView * shapImageView;

@property (readwrite, nonatomic, strong) TencentLBSLocationManager *locationManager;

@property (nonatomic) CLLocationCoordinate2D userCoordinate;

@property (nonatomic,strong)NSMutableArray *dataArr;

@property (nonatomic,strong) NodataView * noDataView;

@property (nonatomic,strong) UIView * tableViewHeaderView;

@end

static int pageIndex = 1;

static NSString * const OrderDetailTableViewCellID = @"OrderDetailTableViewCellID";

static CGFloat const downShapWidth = 13;

@implementation SsehHomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self baseSetting];
    [self getYinlongBanners];
    [self creatRefreshHeader];
    [self creatRefreshAutoNormalFooter];
}

-(void)baseSetting{
    
    self.navigationItem.title = @"一步e家";
    self.ssehTableView.tableHeaderView = self.tableViewHeaderView;
    [self.locationManager startUpdatingLocation];
    CGFloat widthLabel = [@"上海市" widthWithFont:[UIFont systemFontOfSize:14] constrainedToHeight:20];
    
    self.leftTitleItemLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, widthLabel+downShapWidth+3, 44)];;
    self.leftTitleItemLabel.text = @"上海市";
    self.leftTitleItemLabel.font = [UIFont systemFontOfSize:14];
    self.leftTitleItemLabel.textColor = [UIColor whiteColor];
    self.leftTitleItemLabel.userInteractionEnabled = YES;
    self.leftTitleItemLabel.textAlignment = NSTextAlignmentLeft;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:self.leftTitleItemLabel];
    
    UITapGestureRecognizer * leftTitleLabelTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(leftItemClick:)];
    [self.leftTitleItemLabel addGestureRecognizer:leftTitleLabelTap];
    
    self.shapImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"downShap"]];
    self.shapImageView.frame = CGRectMake(widthLabel+3, 17.5, downShapWidth, 9);
    self.shapImageView.userInteractionEnabled = YES;
    [self.leftTitleItemLabel addSubview:self.shapImageView];
    
    [self cityDataArr];
    
    self.navigationController.navigationBar.translucent = NO;
}

-(void)leftItemClick:(UITapGestureRecognizer *)tap{
        
    SDCityPickerViewController *city =[[SDCityPickerViewController alloc]init];
    city.dataArr = self.dataArr;
    [self.navigationController pushViewController:city animated:YES];
    
    city.cityPickerBlock = ^(SDCityModel *city)
    {
        CGFloat widthLabel = [city.name widthWithFont:[UIFont systemFontOfSize:14] constrainedToHeight:20];
        self.leftTitleItemLabel.frame = CGRectMake(0, 0, widthLabel+downShapWidth+3, 44);
        self.leftTitleItemLabel.text  = city.name;
        self.shapImageView.frame = CGRectMake(widthLabel+3, 17.5, downShapWidth, 9);
        
    };
    city.againLocationClick = ^{
        [self.locationManager startUpdatingLocation];
    };
}

#pragma mark - 定位

- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager
                 didFailWithError:(NSError *)error {
    CLAuthorizationStatus authorizationStatus = [CLLocationManager authorizationStatus];
    if (authorizationStatus == kCLAuthorizationStatusDenied || authorizationStatus == kCLAuthorizationStatusRestricted) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"定位权限未开启，是否开启？" preferredStyle:  UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if( [[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]] ) {
                if (@available(iOS 10.0, *)) {
                    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{}completionHandler:^(BOOL success) {
                    }];
                } else {
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                }
            }
        }]];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        }]];
        
        [self presentViewController:alert animated:true completion:nil];
        
    }
}

- (void)tencentLBSLocationManager:(TencentLBSLocationManager *)manager
                didUpdateLocation:(TencentLBSLocation *)location {
    
    [self.locationManager stopUpdatingLocation];

    if (!kStringIsEmpty(location.city)) {
        CGFloat widthLabel = [location.city widthWithFont:[UIFont systemFontOfSize:14] constrainedToHeight:20];
        self.leftTitleItemLabel.frame = CGRectMake(0, 0, widthLabel+downShapWidth+3, 44);
        self.leftTitleItemLabel.text = location.city;
        self.shapImageView.frame = CGRectMake(widthLabel+3, 17.5, downShapWidth, 9);
    }
    //wgs84
    self.userCoordinate = location.location.coordinate;
    
}

#pragma mark - 轮播图

//轮播图
-(void)getYinlongBanners{
    
    NSDictionary * par = @{@"banner_range":@"2"};
    [[QYNetManager sharedManager]POST:kGetYinlongBanners parameters:par andApiTyp:SsehApiTypGetOrders SuccessBlock:^(id responseObject) {
        
        if ([responseObject[@"status"] isEqualToString:@"ok"]) {
            self.bannerModel = [BannerModel yy_modelWithDictionary:responseObject];
            [self layoutbannerImage];
        }else{
            [self showTipWithTitle:responseObject[@"error"]];
        }
        
    } Failure:^(NSError *error) {
        [self showTipWithTitle:SsehPoolNetStr];
    }];
}

-(void)layoutbannerImage{
    
    if (kArrayIsEmpty(self.bannerModel.data)) {
        return;
    }
    
    NSMutableArray * imageMarr = [[NSMutableArray alloc]init];
    for (NSInteger i = 0; i < self.bannerModel.data.count; i++) {
        BannerInfoModel * model = self.bannerModel.data[i];
        NSString * imageUrl = [NSString stringWithFormat:@"%@%@",kSsehImageIP,model.banner_img];
        [imageMarr addObject:imageUrl];
    }
    
    self.carouselView.imageArray = imageMarr;
    
}

-(void)creatRefreshHeader{
    
    self.ssehTableView.mj_header = [SsehMJHeaderTool headerWithRefreshingBlock:^{
        pageIndex = 1;
        //请求数据
        NSDictionary * par = @{@"member_id":[NSString emptyStr:DEF_PERSISTENT_GET_OBJECT(SsehUserID)],
                               @"member_token":[NSString emptyStr:DEF_PERSISTENT_GET_OBJECT(SsehUserToken)],
                               @"page":[NSString stringWithFormat:@"%d",pageIndex],
                               @"order_state":@""
                               };
        [[QYNetManager sharedManager]POST:kGetWorkerOrders parameters:par andApiTyp:SsehApiTypGetOrders SuccessBlock:^(id responseObject) {
            [self.ssehTableView.mj_header endRefreshing];
            
            if ([responseObject[@"status"] isEqualToString:@"ok"]) {
                OrderInforModel * dataModel = [OrderInforModel yy_modelWithDictionary:responseObject];
                [self.dataSource removeAllObjects];
                if (!kArrayIsEmpty(dataModel.data)) {
                    [self.dataSource addObjectsFromArray:dataModel.data];
                    [self.ssehTableView reloadData];
                    if (self.noDataView != nil) {
                        [self.noDataView removeFromSuperview];
                    }
                    self.tableViewHeaderView.frame = CGRectMake(0, 0, VIEW_WIDTH, 155);
                }else{
                    [self.tableViewHeaderView addSubview:self.noDataView];
                    self.tableViewHeaderView.frame = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT-NAVIGATION_BAR_HEIGHT-HOME_INDICATOR_HEIGHT-TAB_BAR_HEIGHT);
                }
            }else{
                [self showErrorTipWithTitle:responseObject[@"error"]];
            }
            
        } Failure:^(NSError *error) {
            [self.ssehTableView.mj_header endRefreshing];
            [self showErrorTipWithTitle:SsehPoolNetStr];
        }];
        
    }];
    [self.ssehTableView.mj_header beginRefreshing];
    
}

-(void)creatRefreshAutoNormalFooter{
    self.ssehTableView.mj_footer = [SsehMJFooterTool footerWithRefreshingBlock:^{
        if (kArrayIsEmpty(self.dataSource)) {
            pageIndex = 1;
        }else{
            pageIndex ++;
        }
        NSDictionary * par = @{@"member_id":DEF_PERSISTENT_GET_OBJECT(SsehUserID),@"member_token":DEF_PERSISTENT_GET_OBJECT(SsehUserToken),@"page":[NSString stringWithFormat:@"%d",pageIndex],@"order_state":@""};
        [[QYNetManager sharedManager]POST:kGetWorkerOrders parameters:par andApiTyp:SsehApiTypGetOrders SuccessBlock:^(id responseObject) {
            [self.ssehTableView.mj_footer endRefreshing];
            if ([responseObject[@"status"] isEqualToString:@"ok"]) {
                OrderInforModel * dataModel = [OrderInforModel yy_modelWithDictionary:responseObject];
                if (!kArrayIsEmpty(dataModel.data)) {
                    [self.dataSource addObjectsFromArray:dataModel.data];
                    [self.ssehTableView reloadData];
                    [self.noDataView removeFromSuperview];
                }else{
                    [self.tableViewHeaderView addSubview:self.noDataView];
                }
                if (kArrayIsEmpty(self.dataSource)) {
                    [self.tableViewHeaderView addSubview:self.noDataView];
                    self.tableViewHeaderView.frame = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT-NAVIGATION_BAR_HEIGHT-HOME_INDICATOR_HEIGHT-TAB_BAR_HEIGHT);
                }else{
                    if (self.noDataView != nil) {
                        [self.noDataView removeFromSuperview];
                    }
                    self.tableViewHeaderView.frame = CGRectMake(0, 0, VIEW_WIDTH, 155);
                }
                
            }else{
                [self showErrorTipWithTitle:responseObject[@"error"]];
            }
            
            
        } Failure:^(NSError *error) {
            [self.ssehTableView.mj_footer endRefreshing];
            [self showErrorTipWithTitle:SsehPoolNetStr];
        }];
    }];
    
}

#pragma mark - tableView

-(UITableView *)ssehTableView{
    
    if (_ssehTableView == nil) {
        self.ssehTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT-TAB_BAR_HEIGHT-NAVIGATION_BAR_HEIGHT) style:UITableViewStylePlain];
        self.ssehTableView.delegate = self;
        self.ssehTableView.dataSource = self;
        self.ssehTableView.backgroundColor = [UIColor backGroudColorForView];
        self.ssehTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.ssehTableView.showsVerticalScrollIndicator = NO;
        self.ssehTableView.showsHorizontalScrollIndicator = NO;
        [self.ssehTableView registerNib:[UINib nibWithNibName:@"OrderDetailTableViewCell" bundle:nil] forCellReuseIdentifier:OrderDetailTableViewCellID];
        [self.view addSubview:self.ssehTableView];
        
        self.ssehTableView.estimatedRowHeight = 240;
        
    }
    return _ssehTableView;
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    OrderDetailsViewController * vc = [[OrderDetailsViewController alloc]init];
    OrderDetail * model = self.dataSource[indexPath.row];
    vc.orderModel = model;
    [self.navigationController pushViewController:vc animated:YES];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    OrderDetailTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:OrderDetailTableViewCellID];
    OrderDetail * model = self.dataSource[indexPath.row];
    [cell configData:model andSsehOrderType:SsehOrderTypeHomePage andIndexPath:indexPath];
    __weak typeof (self)weakSelf = self;
    cell.leftButtonClick = ^(NSIndexPath *index) {
        [weakSelf refuseWorkerOrderApi:model];
    };
    
    cell.midButtonClick = ^(NSIndexPath *index) {
 
        //需要先获取一下经纬度
        double lat = model.maintailOrderAddressBean.address_latitude.doubleValue;
        double lon = model.maintailOrderAddressBean.address_longitude.doubleValue;
        [weakSelf navigationAlert:CLLocationCoordinate2DMake(lat, lon)];
    };
    
    cell.rightButtonClick = ^(NSIndexPath *index, OrderDetail *orderModel) {
        AddMaterialsViewController * vc = [[AddMaterialsViewController alloc]init];
        vc.orderModel = orderModel;
        [weakSelf.navigationController pushViewController:vc animated:YES];
        
    };
    
    
    return cell;
    
}

#pragma mark - 拒绝订单
-(void)refuseWorkerOrderApi:(OrderDetail *)model{
    
    UIAlertAction * act1 = [UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    UIAlertAction * act2 = [UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self cancleOrder:model];
    }];
    UIAlertController * aleVC = [UIAlertController alertControllerWithTitle:nil message:@"确认取消该订单？" preferredStyle:UIAlertControllerStyleAlert];
    [aleVC addAction:act1];
    [aleVC addAction:act2];
    [self presentViewController:aleVC animated:YES completion:nil];
    
}

-(void)cancleOrder:(OrderDetail *)model{
    
    //member_id    member_token  order_id
    [self showLoading];
    NSDictionary * par = @{@"member_id":[NSString emptyStr:DEF_PERSISTENT_GET_OBJECT(SsehUserID)],@"member_token":[NSString emptyStr:DEF_PERSISTENT_GET_OBJECT(SsehUserToken)],@"order_id":model.order_id};
    [[QYNetManager sharedManager]POST:kRefuseWorkerOrder parameters:par andApiTyp:SsehApiTypGetOrders SuccessBlock:^(id responseObject) {
        [self hideLoading];
        if ([responseObject[@"status"] isEqualToString:@"ok"]) {
            [self showTipWithTitle:@"取消订单成功！"];
            [self creatRefreshHeader];
        }else{
            [self showTipWithTitle:responseObject[@"error"]];
        }
    } Failure:^(NSError *error) {
        [self hideLoading];
        [self showErrorTipWithTitle:SsehPoolNetStr];
    }];
    
}

#pragma mark - 导航
-(void)navigationAlert:(CLLocationCoordinate2D)coor{
    
    UIAlertAction * act1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    UIAlertAction * act = [UIAlertAction actionWithTitle:@"用腾讯地图导航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [self useQQMap:coor];
    }];
    UIAlertAction * act2 = [UIAlertAction actionWithTitle:@"用自带地图导航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        [self iphoneMap:coor];
    }];

    UIAlertAction * act3 = [UIAlertAction actionWithTitle:@"用百度地图导航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self baiduMap:coor];
    }];
    UIAlertAction * act4 = [UIAlertAction actionWithTitle:@"用高德地图导航" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self gaodeMap:coor];
    }];
    
    UIAlertController * aleVC = [UIAlertController alertControllerWithTitle:nil message:@"请选择导航地图" preferredStyle:UIAlertControllerStyleActionSheet];
    [aleVC addAction:act1];
    [aleVC addAction:act];
    [aleVC addAction:act2];
    [aleVC addAction:act3];
    [aleVC addAction:act4];
    
    [self presentViewController:aleVC animated:YES completion:nil];
    
}

-(void)useQQMap:(CLLocationCoordinate2D)coor{
    //coor = CLLocationCoordinate2DMake(31.13184, 121.463718);
    NSString *urlStr;
    if (@available(iOS 9.0, *)) {
        urlStr = [[NSString stringWithFormat:@"qqmap://map/routeplan?from=我的位置type=drive&tocoord=%f,%f&policy=1",coor.latitude,coor.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet  URLQueryAllowedCharacterSet]];
    } else {
        urlStr = [[NSString stringWithFormat:@"qqmap://map/routeplan?from=我的位置type=drive&tocoord=%f,%f&policy=1",coor.latitude,coor.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }
    NSURL * r = [NSURL URLWithString:urlStr];
    
    if ([[UIApplication sharedApplication] canOpenURL:r]){
        [[UIApplication sharedApplication] openURL:r];
    }else{
        [self showErrorTipWithTitle:@"未安装腾讯地图"];
    }
}

-(void)iphoneMap:(CLLocationCoordinate2D)coor{

    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com"]]){
        MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
        MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coor addressDictionary:nil]];
        [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
                       launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,
                                       MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
    }else{
        [self showErrorTipWithTitle:@"未安装苹果地图"];
    }
    
}

-(void)baiduMap:(CLLocationCoordinate2D)coor{
    
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
        CLLocationCoordinate2D bdCoor = [SsehLocationConverter wgs84ToBd09:coor];
        NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/ridenavi?destination=%f,%f&src=ios.baidu.openAPIdemo", bdCoor.latitude, bdCoor.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSURL *url = [NSURL URLWithString:urlString];
        [[UIApplication sharedApplication] openURL:url];
    }else{
        [self showErrorTipWithTitle:@"未安装百度地图"];
    }
}

-(void)gaodeMap:(CLLocationCoordinate2D)coor{

    
    NSURL *scheme = [NSURL URLWithString:@"iosamap://"];
    BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:scheme];
    if (!canOpen) {
        [self showErrorTipWithTitle:@"未安装高德地图"];
        return;
    }
    NSString * urlStr = [NSString stringWithFormat:@"iosamap://navi?sourceApplication=applicationName&poiname=fangheng&poiid=BGVIS&lat=%f1&lon=%f&dev=1&style=2",coor.latitude,coor.longitude];
    NSURL *myLocationScheme = [NSURL URLWithString:urlStr];
    if (@available(iOS 10.0, *)) {
        [[UIApplication sharedApplication] openURL:myLocationScheme options:@{} completionHandler:^(BOOL success) {
            
        }];
    } else {
        [[UIApplication sharedApplication] openURL:myLocationScheme];
    }
    
}

-(NSMutableArray *)dataSource{
    
    if (_dataSource == nil) {
        _dataSource = [[NSMutableArray alloc]initWithCapacity:0];
    }
    return _dataSource;
    
}

-(XRCarouselView *)carouselView{
    
    if (_carouselView == nil) {
        _carouselView = [[XRCarouselView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 155)];
        _carouselView.time = 3;
        _carouselView.pagePosition = PositionBottomCenter;
        _carouselView.changeMode = ChangeModeFade;
    }
    return _carouselView;
}


-(TencentLBSLocationManager *)locationManager{
    if (_locationManager == nil) {
        _locationManager = [[TencentLBSLocationManager alloc] init];
        [_locationManager setDelegate:self];
        [_locationManager setPausesLocationUpdatesAutomatically:NO];
        [self.locationManager setRequestLevel:TencentLBSRequestLevelAdminName];
        [_locationManager setApiKey:@"XR6BZ-CQRCP-W7EDB-LPXT7-LTGAS-Z3BE2"];
        
        CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
        if (authorizationStatus == kCLAuthorizationStatusNotDetermined) {
            [_locationManager requestWhenInUseAuthorization];
        }
        
    }
    return _locationManager;
}

-(void)cityDataArr{
    
    NSString *path =[[NSBundle mainBundle]pathForResource:@"City" ofType:@"plist"];
    
    NSArray *arr =[NSArray arrayWithContentsOfFile:path];
    
    NSMutableArray *cityModels = [NSMutableArray array];
    
    //获取全部城市cityModel
    for (NSDictionary *dic in arr){
        for (NSDictionary *dict in dic[@"children"]){
            SDCityModel *cityModel = [SDCityModel cityWithDict:dict];
            [cityModels addObject:cityModel];
        }
    }
    
    //获取首字母
    NSMutableArray *indexArr =
    [[cityModels valueForKeyPath:@"firstLetter"] valueForKeyPath:@"@distinctUnionOfObjects.self"];
    
    //遍历数组
    for (NSString *indexStr in indexArr) {
        
        SDCityInitial *cityInitial =[[SDCityInitial alloc]init];
        cityInitial.initial = indexStr;
        NSMutableArray *cityArrs =[NSMutableArray array];
        for ( SDCityModel *cityModel in cityModels) {
            if ([indexStr isEqualToString:cityModel.firstLetter]) {
                [cityArrs addObject:cityModel];
            }
        }
        cityInitial.cityArrs = cityArrs;
        [self.dataArr addObject:cityInitial];
    }
}

-(NSMutableArray *)dataArr{

    if (_dataArr == nil) {
        _dataArr = [[NSMutableArray alloc]initWithCapacity:0];
    }
    return _dataArr;
    
}

-(NodataView *)noDataView{
    
    if (_noDataView == nil) {
        _noDataView = [[NodataView alloc]initWithFrame:CGRectMake(0, 155, VIEW_WIDTH, VIEW_HEIGHT-NAVIGATION_BAR_HEIGHT-155-TAB_BAR_HEIGHT)];
        _noDataView.centerImage = [UIImage imageNamed:@"noOrder"];
        _noDataView.titleStr = @"暂无订单";
        
    }
    return _noDataView;
}

-(UIView *)tableViewHeaderView{
    
    if (_tableViewHeaderView == nil) {
        _tableViewHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 155)];
        [_tableViewHeaderView addSubview:self.carouselView];
    }
    return _tableViewHeaderView;
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = NO;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
